<?php
class Ext_View_Helper_FormDate extends Zend_View_Helper_FormElement
{
    public function formDate($name, $value = null, $attribs = null)
    {
        $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable

        // build the element
        $disabled = '';
        if ($disable) {
            // disabled
            $disabled = ' disabled="disabled"';
        }
        
        // XHTML or HTML end tag?
        $endTag = ' />';
        if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
            $endTag= '>';
        }
		$xhtml = "\n<script>\n"
			. "$(function() {\n\t"
			. "$(\"#". $this->view->escape($id) ."\").datepicker( { dateFormat: 'dd/mm/yy' } );\n"
			. "});\n"
			. "</script>\n\n";
        $xhtml .= '<input type="text"'
                . ' name="' . $this->view->escape($name) . '"'
                . ' id="' . $this->view->escape($id) . '"'
                . ' value="' . $this->view->escape(is_null($value)?"":$value->toString(Ext_Form_Element_Date::DATE_FORMAT) ) . '"'
                . $disabled
                . $this->_htmlAttribs($attribs)
                . $endTag;

        return $xhtml;
    }
}
